package com.alphasta.project.ucp.usermapping.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alphasta.common.utils.GUID;
import com.alphasta.framework.aspectj.lang.annotation.Log;
import com.alphasta.framework.aspectj.lang.constant.BusinessType;
import com.alphasta.project.ucp.usermapping.domain.Usermapping;
import com.alphasta.project.ucp.usermapping.service.IUsermappingService;
import com.alphasta.framework.web.controller.BaseController;
import com.alphasta.framework.web.page.TableDataInfo;
import com.alphasta.framework.web.domain.AjaxResult;

/**
 * InnoDB free: 173056 kB 信息操作处理
 *
 * @author 张炳威
 * @date 2019-08-08
 */
@Controller
@RequestMapping("/ucp/usermapping")
public class UsermappingController extends BaseController
{
    private String prefix = "ucp/usermapping";

	@Autowired
	private IUsermappingService usermappingService;

	@RequiresPermissions("ucp:usermapping:view")
	@GetMapping()
	public String usermapping()
	{
	    return prefix + "/usermapping";
	}

	/**
	 * 查询InnoDB free: 173056 kB列表
	 */
	@RequiresPermissions("ucp:usermapping:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Usermapping usermapping)
	{
		startPage();
        List<Usermapping> list = usermappingService.selectUsermappingList(usermapping);
		return getDataTable(list);
	}

	/**
	 * 新增InnoDB free: 173056 kB
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 新增保存InnoDB free: 173056 kB
	 */
	@RequiresPermissions("ucp:usermapping:add")
	@Log(title = "InnoDB free: 173056 kB", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Usermapping usermapping)
	{
		usermapping.setUsermpid(new GUID().toString());
		return toAjax(usermappingService.insertUsermapping(usermapping));
	}

	/**
	 * 修改InnoDB free: 173056 kB
	 */
	@GetMapping("/edit/{usermpid}")
	public String edit(@PathVariable("usermpid") String usermpid, ModelMap mmap)
	{
		Usermapping usermapping = usermappingService.selectUsermappingById(usermpid);
		mmap.put("usermapping", usermapping);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存InnoDB free: 173056 kB
	 */
	@RequiresPermissions("ucp:usermapping:edit")
	@Log(title = "InnoDB free: 173056 kB", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Usermapping usermapping)
	{
		return toAjax(usermappingService.updateUsermapping(usermapping));
	}

	/**
	 * 删除InnoDB free: 173056 kB
	 */
	@RequiresPermissions("ucp:usermapping:remove")
	@Log(title = "InnoDB free: 173056 kB", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		return toAjax(usermappingService.deleteUsermappingByIds(ids));
	}

}
